package com.leet.string;

public class SubStr {
    public int strStr(String haystack, String needle) {
        int len1 = haystack.length(),len2 = needle.length();
        int i = 0,j = 0,pre = 0;
        while(pre < len1 && j < len2){
            i = pre;
            while (i < len1 && j < len2 && haystack.charAt(i) == needle.charAt(j)){
                i++;
                j++;
            }
            if(j == len2) return pre;
            else {
                pre++;
                j = 0;
            }
        }
        return -1;
    }
}
